package com.example.dyxeapplication.menu.ejaan;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

import com.example.dyxeapplication.R;

public class Menu_Ejaan_Belajar extends Activity {
	// ---the images to display---
	Integer[] imageIDs = { R.drawable.ae, R.drawable.bd, R.drawable.co,
			R.drawable.ft, R.drawable.gjy, R.drawable.hnr, R.drawable.il,
			R.drawable.kx, R.drawable.mw, R.drawable.pq, R.drawable.sz,
			R.drawable.uv };

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu_belajar);
		GridView gridView = (GridView) findViewById(R.id.gridview);
		gridView.setAdapter(new ImageAdapter(this));
		gridView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				Intent myIntent = null;
				switch (position) {
				case 0:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_AE.class);
					break;
				case 1:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_BD.class);
					break;
				case 2:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_CO.class);
					break;
				case 3:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_FT.class);
					break;
				case 4:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_GJY.class);
					break;
				case 5:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_HNR.class);
					break;
				case 6:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_IL.class);
					break;
				case 7:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_KX.class);
					break;
				case 8:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_MW.class);
					break;
				case 9:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_PQ.class);
					break;
				case 10:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_SZ.class);
					break;
				case 11:
					myIntent = new Intent(v.getContext(), Menu_Ejaan_UV.class);
					break;
				}
				startActivity(myIntent);
			}
		});
	}

	public class ImageAdapter extends BaseAdapter {
		private Context context;

		public ImageAdapter(Context c) {
			context = c;
		}

		// ---returns the number of images---
		public int getCount() {
			return imageIDs.length;
		}

		// ---returns the ID of an item---
		public Object getItem(int position) {
			return position;
		}

		// ---returns the ID of an item---
		public long getItemId(int position) {
			return position;
		}

		// ---returns an ImageView view---
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView imageView;
			if (convertView == null) {
				imageView = new ImageView(context);
				//imageView.setLayoutParams(new GridView.LayoutParams(210, 110));
				imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);

			} else {

				imageView = (ImageView) convertView;
			}
			imageView.setImageResource(imageIDs[position]);
			return imageView;
		}
	}
	
	@Override
	public void onBackPressed() {
		Intent backIntent = new Intent(this, Menu_Ejaan.class);
		backIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    startActivity(backIntent);
	}

}
